import { importProvidersFrom, isDevMode, makeEnvironmentProviders } from '@angular/core';
import { SystemState } from './system/system.state';
import { NgxsModule } from '@ngxs/store';
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
import { NgxsFormPluginModule } from '@ngxs/form-plugin';
import { NgxsRouterPluginModule, RouterStateSerializer } from '@ngxs/router-plugin';
import { CustomRouterStateSerializer } from './router/custom-router-state-serializer';

export const states = [
  SystemState,
];

export function provideNgxs() {
  return makeEnvironmentProviders([
    importProvidersFrom(NgxsModule.forRoot([...states], {developmentMode: isDevMode()})),
    importProvidersFrom(NgxsStoragePluginModule.forRoot()),
    importProvidersFrom(NgxsFormPluginModule.forRoot()),
    importProvidersFrom(NgxsRouterPluginModule.forRoot()),
    {provide: RouterStateSerializer, useClass: CustomRouterStateSerializer},
  ]);
}
